package com.kungfuhacking.wristbandpro.login.activity;

import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.TextView;

import com.kungfuhacking.wristbandpro.R;
import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
import com.kungfuhacking.wristbandpro.custom.InputView;
import com.kungfuhacking.wristbandpro.custom.TitleBarView;
import com.kungfuhacking.wristbandpro.login.presenter.ISetPwdPresenter;
import com.kungfuhacking.wristbandpro.login.view.ISetPwdView;
import com.kungfuhacking.wristbandpro.utils.LogUtil;

import static android.content.ContentValues.TAG;


/**
 * 注册输入密码页面
 * <p>
 * Created by Aaron on 17/3/29.
 */

public class SetPwdActivity extends BaseActivity implements View.OnClickListener, ISetPwdView {

    private InputView ivpwd;
    InputView ivpwdrepet;
    private TextView tv_done;
    private TitleBarView tbv;
    //    private String TAG = getClass().getSimpleName();
    private String token;
    private String tel;
    ISetPwdPresenter iSetPwdPresenter = new ISetPwdPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_register_pwd);

        initWidget();

        if (bundle != null) {
            token = bundle.getString("token");
            tel = bundle.getString("tel");
        }

        LogUtil.e(TAG, "token : " + token);

    }

    private void initWidget() {

        this.tv_done = (TextView) findViewById(R.id.tv_done);
        this.ivpwdrepet = (InputView) findViewById(R.id.iv_pwd_repet);
        this.ivpwd = (InputView) findViewById(R.id.iv_pwd);
        tbv = (TitleBarView) findViewById(R.id.tbv);

        ivpwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        ivpwdrepet.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

        tbv.setOnLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tv_done.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.tv_done://设置密码
                iSetPwdPresenter.setPwd(token);
                break;

        }
    }

    @Override
    public String getPassword() {
        return ivpwd.getText();
    }

    @Override
    public String getPasswordAgain() {
        return ivpwdrepet.getText();
    }

    @Override
    public String getAccount() {
        return tel;
    }

    @Override
    public String getToken() {
        return token;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        iSetPwdPresenter.clearRequest();
    }

}
